<?php
namespace app\yangxt_forum_admin\controller;
use think\Controller;
class Admin extends Controller
{
	// 管理员登录页面 1803010340
	 public function aLogin()
    {	

    	return view();
    }
    // 执行登陆 1803010340
    public function aDoLogin()
    {	
    	$aname=input("auser");
        $apassword=input("apasswd");
        // find查询 1803010340
        $re = db("admin")
        ->where("admin",$aname)
        ->where("apa",$apassword)
        ->find();
        if($re!=null){
            session("admin",$aname);
            $this -> success( session("admin")."登录成功","yangxt_forum_admin/deal/mesDeal");
        }
        else{
            $this -> error("登录失败","yangxt_forum_admin/admin/alogin");
        }
    	
    }
  
    // 管理员改密页面 1803010340
    public function aPa()
    {	
    	return view();
    }
    // 执行修改密码 1803010340
    public function aDoPa()
    {	
    	$user=session('admin');
    	$oldpa=input('oldpasswd');
    	$newpa=input('newpasswd1');
    	$re = db('admin')
            ->where('admin',$user)
            ->where('apa',$oldpa)
            ->setField('apa',$newpa);
         if ($re==1) {
         	$this -> success("密码修改成功,请重新登录！","yangxt_forum_admin/admin/alogin");
         }
         else
         {
         	$this -> error("密码修改失败","yangxt_forum_admin/admin/apa");
         }
    }

    // 注销 1803010340
    public function aDoOut()
    {	
    	$this -> acheck();
        // 清除 1803010340
         session('admin',null);
        // 跳转 1803010340
        $this -> success("管理员注销成功","yangxt_forum_admin/admin/alogin");
    }
    public function aCheck(){
        if(!session('?admin')){
            $this->error("请登录","admin/alogin");
        }
    }
}